#ifndef __GRID_GUI_H__
#define __GRID_GUI_H__

#include <Windows.h>
#include <map>
#include <vector>
#include <string>

#define MAX_ROW_NAME "MaxRowName"
#define MAX_COL_NAME "MaxColName"
#define COMMON_PEN_WIDTH 1
#define SELECTED_PEN_WIDTH 4
#define TEXT_FONT_SIZE 22
#define TEXT_FONT_NAME "Microsoft Sans Serif"

#define DARK_COLOR_BACKGROUND_1 RGB(0, 0, 0) 
#define DARK_COLOR_BACKGROUND_2 RGB(58, 67, 74)
#define DARK_COLOR_BACKGROUND_3 RGB(37, 42, 46)
#define DARK_COLOR_BACKGROUND_4 RGB(28, 32, 43)
#define DARK_COLOR_BACKGROUND_5 RGB(33, 24, 25)
#define DARK_COLOR_FONT_1 RGB(255, 255, 255)
#define DARK_COLOR_FONT_2 RGB(153, 161, 167)
#define LIGHT_COLOUR_BACKGROUND_1 RGB(252, 252, 252)
#define LIGHT_COLOUR_BACKGROUND_2 RGB(252, 252, 252)
#define LIGHT_COLOUR_BACKGROUND_3 RGB(239, 243, 247)
#define LIGHT_COLOUR_BACKGROUND_4 RGB(255, 255, 255)
#define LIGHT_COLOUR_BACKGROUND_5 RGB(255, 255, 255)
#define LIGHT_COLOUR_FONT_1 RGB(0, 0, 0) 
#define LIGHT_COLOUR_FONT_2 RGB(0, 0, 0) 

using namespace std;

typedef struct
{
	char szName[128 + 1], szValue[128 + 1], szFontName[128 + 1];
	int iLeft, 
		iTop, 
		iWidth, 
		iHeight, 
		iRowSpace, 
		iColSpace, 
		iAlign, 
		iFontSize, 
		iRowNo,
		iColNo;
}ST_CELL_INFO;

class CGridGui
{
public:
	~CGridGui();
	const bool InitCanvas(::HDC ptrDc, const int iTop, const int iLeft, const int iWidth, const int iHeight);
	const void DelObj();
	const void UnInit();
	int GetTop();
	void SetTop(const int iTop);
	int GetLeft();
	void SetLeft(const int iLeft);
	void InitCell(const int iRow, const int iCol, const int iWidth, const int iHeight, const char * pszName, 
				  const int iLeft = 0, const int iTop = 0, const int iRowSpace = 1, const int iColSpace = 1, int iAlign = 1, 
				  int iFontSize = 20, const char * pszFontName = "");
	void DrawBmp(const char * pszFileName);
	void DrawCellBorder(const int iRow, const int iCol, const int iPenWidth, const COLORREF dwColor);
	void FillColor(::RECT & refRect, const COLORREF dwColor);
	void FillColor(const int iRow, const int iCol, const COLORREF dwColor);
	void DrawLine(const int iBgnRow, const int iBgnCol, const int iEndRow, const int iEndCol);
	void DrawLine(const char * pszBgnName, const char * pszEndName);
	void DrawCell(const char * pszName, const char * pszValue, const COLORREF dwFontColor, const COLORREF dwBackgroundColor, bool bDraLine = false);
	void InitRect(const int iLeft, const int iTop, const int iWidth, const int iHeight, RECT & refRect);
	COLORREF GetBackgroundColor();
	void SetBackgroundColor(const COLORREF dwBackgroundColor);
	void RefreshView(HDC ptrImgDC, const int iLeft, const int iTop, const int iWidth, const int iHeight);
	bool GetCellInfo(int iRow, int iCol, ST_CELL_INFO & StCellInfo);
	bool GetCellInfo(const char * pszName, ST_CELL_INFO & StCellInfo);

private:
	ST_CELL_INFO * _GetCellInfo(int iRow, int iCol);
	bool _GetCellInfo(int iRow, int iCol, ST_CELL_INFO & StCellInfo);
	bool _GetCellInfo(const char * pszName, ST_CELL_INFO & StCellInfo);
	int GetCellPos(int iRow, const int iCol, const int iLeft, const int iTop, ST_CELL_INFO & StCellInfo);
	void _DrawCellBorder(const int iRow, const int iCol, const int iPenWidth, const COLORREF dwColor);
	void _FillColor(::RECT & refRect, const COLORREF dwColor);
	void _FillColor(const int iRow, const int iCol, const COLORREF dwColor);
	void _DrawCell(const char * pszName, const char * pszValue, const COLORREF dwFontColor, const COLORREF dwBackgroundColor, bool bDraLine);
	void _RefreshView(HDC ptrImgDC, const int iLeft, const int iTop, const int iWidth, const int iHeight);
	void _DrawLine(const int iBgnRow, const int iBgnCol, const int iEndRow, const int iEndCol);
	void _DrawLine(const char * pszBgnName, const char * pszEndName);	
private:
	map<string, ST_CELL_INFO *> m_mpCellIfno;
	map<string, string> m_mpFieldInfo;
	int m_iTop, m_iLeft;
	bool m_bUnFlg;
	::HBITMAP m_ptrBmp;
	::HDC m_ptrMemDC;
	COLORREF m_dwBackgroundColor;
};

#endif//__GRID_GUI_H__